package com.ecommerce.dal.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ecommerce.dal.dao.IItemPhotoDAO;
import com.ecommerce.dal.entity.ItemPhoto;
import com.ecommerce.dal.util.CustomHibernateDAOSupport;

@Repository("itemPhotoDAO")
public class ItemPhotoDAO extends CustomHibernateDAOSupport implements
		IItemPhotoDAO {

	@Override
	public void save(ItemPhoto itemPhoto) {
		getHibernateTemplate().save(itemPhoto);

	}

	@Override
	public void update(ItemPhoto itemPhoto) {
		getHibernateTemplate().update(itemPhoto);

	}

	@Override
	public void delete(ItemPhoto itemPhoto) {
		getHibernateTemplate().delete(itemPhoto);

	}

	@Override
	public List<ItemPhoto> findByItemId(long itemId) {
		List list = getHibernateTemplate().find(
				"select itemPhoto from ItemPhoto itemPhoto inner join itemPhoto.item item where item.itemId = ?", itemId);
		return ((list != null && list.size()>0) ?  list : null) ;
	}

}
